package com.sky.sd.system.controller;

import com.sky.sd.common.web.response.Result;
import com.sky.sd.system.bean.dto.BasicPair;
import com.sky.sd.system.bean.dto.BasicPairNode;
import com.sky.sd.system.service.IBasicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <br/>功能:
 * <br/>版本: 1.0
 * <br/>开发人员: 弓振
 * <br/>创建日期: 2020/7/3 10:44
 * <br/>修改日期: 2020/7/3 10:44
 * <br/>修改列表:
 */
@RestController
@RequestMapping("/system/basic")
@Api(tags = "下拉列表基础数据")
public class BasicController {

    @Autowired
    private IBasicService basicService;

    @GetMapping("/dept")
    @ApiOperation(value = "查询部门树")
    public Result listDept() {
        List<BasicPairNode> nodes = basicService.listDept();
        return Result.success(nodes);
    }
    @GetMapping("/role")
    @ApiOperation(value = "查询角色",notes = "id->value,name->label")
    public Result listRole() {
        List<BasicPair> pairs = basicService.listRole();
        return Result.success(pairs);
    }
    @GetMapping("/roleByType")
    @ApiOperation(value = "根据用户类型查询角色",notes = "id->value,name->label")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "type", value = "用户类型", dataType = "string", paramType = "query", example = "")
    )
    public Result listRoleByList(@RequestParam String type) {
        List<BasicPair> pairs = basicService.listRoleByType(type);
        return Result.success(pairs);
    }
    @GetMapping("/menu")
    @ApiOperation(value = "查询菜单树")
    public Result listMenu() {
        List<BasicPairNode> pairs = basicService.listMenu();
        return Result.success(pairs);
    }
    @GetMapping("/permsByMenuId")
    @ApiOperation(value = "根据菜单查询该菜单关联的权限")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "menuId", value = "菜单id", dataType = "string", paramType = "query", example = "")
    )
    public Result permsByMenuId(@RequestParam(value = "menuId")String menuId) {
        List<BasicPairNode> pairs = basicService.listPermsByMenuId(menuId);
        return Result.success(pairs);
    }
    @GetMapping("/pDic")
    @ApiOperation(value = "查询数据字典项",notes = "id->value,name->label")
    public Result pdic() {
        List<BasicPair> pairs = basicService.lisPDic();
        return Result.success(pairs);
    }
    @GetMapping("/childDicByCode")
    @ApiOperation(value = "根据数据字典编码查询数据子项",notes = "code->value,name->label")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "code", value = "字典编码", dataType = "string", paramType = "query", example = "")
    )
    public Result lisChildDicByCode(String code) {
        List<BasicPair> pairs = basicService.lisChildDicByCode(code);
        return Result.success(pairs);
    }
}
